package com.fg.pro.ai.controller;

import cn.hutool.core.util.BooleanUtil;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.fg.pro.model.reponse.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("aiAssistant")
public class AiAssistant {

    @Autowired
    DashScopeChatModel dashScopeChatModel;

    @Autowired
    private ChatMemory chatMemory;

    @Operation(summary = "人工助手-投诉测试",description = "")
    @GetMapping("/chartByAdviceAndMemory")
    public ResponseResult chartByAdviceAndMemory(@RequestParam(required = false)String question){
        ChatClient chatClient = ChatClient
                .builder(dashScopeChatModel)
                .defaultAdvisors(
                        PromptChatMemoryAdvisor.builder(chatMemory)
                                .conversationId("11112") // 在builder中设置
                                .build()
                )
                .build();
        Boolean flag = chatClient
                .prompt()
                .system("""
                        判断是不是投诉，有没有投诉意图，有直接返回true，否则返回false，只返回true或者false就行。
                        """)
                .user(question)
                .call()
                .entity(Boolean.class);
        String content = "无";
        if(BooleanUtil.isTrue(flag)){
            content = "投诉";
        }else {
            content = "非投诉";
        }


        return ResponseResult.okResult(content);
    }

}
